//
//  USOurListSubCell.m
//  us
//
//  Created by karry on 2025/5/24.
//

#import "USOurListSubCell.h"

@interface USOurListSubCell ()

@property(nonatomic, strong) UIImageView *imgView;

@property(nonatomic, strong) UIButton *doneBtn;
@property(nonatomic, strong) UILabel *titleLab;


@end

@implementation USOurListSubCell

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    return self;
}

- (void)setModel:(USListItemModel *)model {
    _model = model;
    
    if (model.completionStatus == 1) {
        NSDictionary *attributes = @{
            NSStrikethroughStyleAttributeName: @(NSUnderlineStyleSingle),
            NSForegroundColorAttributeName: UIColor.labelColor
        };
        NSAttributedString *attrStr = [[NSAttributedString alloc] initWithString:model.taskTitle attributes:attributes];
        self.titleLab.attributedText = attrStr;
        
        [self.doneBtn setSelected:YES];
    }else {
        self.titleLab.attributedText = nil;
        self.titleLab.text = model.taskTitle;
        
        [self.doneBtn setSelected:NO];
    }

    
 
    self.imgView.hidden = model.taskPicUrl.length == 0;
    
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:model.taskPicUrl.photoThumbnail]];
}

-(void)setupView{
    
    self.contentView.backgroundColor = [UIColor mi_1_color];
    self.contentView.layer.cornerRadius = 14;
    
    self.imgView = [[UIImageView alloc]init];
    [self.contentView addSubview:self.imgView];
    self.imgView.contentMode = UIViewContentModeScaleAspectFill;
    self.imgView.layer.cornerRadius = 12;
    self.imgView.layer.masksToBounds = YES;
    self.imgView.backgroundColor = [UIColor jk_randomColor];
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.height.equalTo(self.imgView.mas_width).multipliedBy(1);
    }];
    
    self.doneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:self.doneBtn];
    [self.doneBtn setImage:[UIImage imageNamed:@"listSub_normal"] forState:UIControlStateNormal];
    [self.doneBtn setImage:[UIImage imageNamed:@"listSub_done"] forState:UIControlStateSelected];
    [self.doneBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.bottom.mas_equalTo(-15);
        make.width.height.mas_equalTo(20);
    }];
    
    self.doneBtn.userInteractionEnabled = NO;
//    [self.doneBtn addTarget:self action:@selector(pettyDoneAction) forControlEvents:UIControlEventTouchUpInside];
    
    self.titleLab = [[UILabel alloc]init];
    [self.contentView addSubview:self.titleLab];
    self.titleLab.font = [UIFont systemFontOfSize:14];
    self.titleLab.textColor = UIColor.labelColor;
    self.titleLab.textAlignment = NSTextAlignmentLeft;
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.doneBtn);
        make.left.equalTo(self.doneBtn.mas_right).offset(4);
        make.right.mas_equalTo(-10);
    }];
}
 

//- (void)pettyDoneAction {
//    if (self.pettyDoneBlock) {
//        self.pettyDoneBlock();
//    }
//}
 
@end
